package com.sskj.b70.p.activity;

import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.CoinFeeBean;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.bean.UserInfo;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.MD5Utils;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.WithdrawActivity;

/**
 * <pre>
 *     author : wk_math
 *     e-mail : wk_math@163.com
 *     time   : 2018/03/30
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class WithdrawPresenter extends BasePresenter<WithdrawActivity> {

    public void sendCode() {
//        String phone = (String) SPUtils.get(MyAppLication.getApplication(), Constants.SP_MOBILE, "");
//        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
//                .params("mobile", phone)
//                .params("type", 5)
        httpService.sendCode(MyAppLication.getMobile(), "")
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        if (httpListData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.startCount();
                        }
                    }
                });
    }

//    public void checkCode(String code) {
//        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHECK_CODE)
//                .params("mobile", MyAppLication.getMobile())
//                .params("code", code)
//                .execute(new JsonCallBack<HttpData>() {
//                    @Override
//                    public void _onSuccess(Response<HttpData> response) {
//                        HttpData httpListData = response.body();
//                        if (httpListData.getStatus() == HttpConfig.STATUS_OK) {
//                            mView.setCodeOk();
//                        } else {
//                            ToastUtil.showShort(httpListData.getMsg());
//                        }
//                    }
//                });
//    }

    public void withdraw(String id, String usdFee, String tradePwd, String code, String walletAddr, String stockCode) {
        // id  出币数量  交易密码  验证码  地址  类型--USDT
        httpService.extractCoin(id, usdFee, MD5Utils.getMd5Value(tradePwd), code, walletAddr, stockCode)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        if (httpListData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.finish();
                        }
                    }
                });
    }

    public void getCoinFee(String code) {
        httpService.getCoin(code)
                .execute(new JsonCallBack<HttpData<CoinFeeBean>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<CoinFeeBean>> response) {
                        HttpData<CoinFeeBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.updateCoin(httpData.getData());
                        }
                    }
                });
    }

    public void getUserInfo() {
        httpService.getUserInfo()
                .execute(new JsonCallBack<HttpData<UserInfo>>() {
                    @Override
                    protected void _onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            mView.updateUserInfo(httpData.getData());
                        }
                    }
                });
    }
}
